﻿using System;
using System.Collections.Generic;
using Character;
using H;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x02000209 RID: 521
public class HStyleChangeUI : MonoBehaviour
{
	// Token: 0x17000173 RID: 371
	// (get) Token: 0x06000E47 RID: 3655 RVA: 0x00059150 File Offset: 0x00057350
	// (set) Token: 0x06000E48 RID: 3656 RVA: 0x00059160 File Offset: 0x00057360
	public bool Interactable
	{
		get
		{
			return this.mainToggle.Interactable;
		}
		set
		{
			this.mainToggle.Interactable = value;
			if (!this.mainToggle.Interactable && this.hideableRoot.gameObject.activeSelf)
			{
				this.hideableRoot.gameObject.SetActive(false);
			}
			else if (this.mainToggle.Interactable && this.mainToggle.Value && !this.hideableRoot.gameObject.activeSelf)
			{
				this.hideableRoot.gameObject.SetActive(true);
			}
		}
	}

	// Token: 0x06000E49 RID: 3657 RVA: 0x000591FC File Offset: 0x000573FC
	private void Awake()
	{
		this.mainToggle.ActionAddListener(new UnityAction<bool>(this.OnChangeMainToggle));
		this.genreToggles[0].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Insert));
		this.genreToggles[1].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Service));
		this.genreToggles[2].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Petting));
		this.stateToggles[0].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Resist));
		this.stateToggles[1].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Flop));
		this.stateToggles[2].ActionAddListener(new UnityAction<bool>(this.OnChangeGenre_Weakness));
		this.hideableRoot.SetActive(false);
	}

	// Token: 0x06000E4A RID: 3658 RVA: 0x000592C4 File Offset: 0x000574C4
	public void Setup(H_Scene h_scene, Dictionary<string, H_StyleData> dictionary)
	{
		this.h_scene = h_scene;
		this.stylesDictionary = dictionary;
		this.styles_inset.Clear();
		this.styles_service.Clear();
		this.styles_petting.Clear();
		foreach (H_StyleData h_StyleData in dictionary.Values)
		{
			if (h_StyleData.type == H_StyleData.TYPE.INSERT)
			{
				this.styles_inset.Add(h_StyleData);
			}
			else if (h_StyleData.type == H_StyleData.TYPE.SERVICE)
			{
				this.styles_service.Add(h_StyleData);
			}
			else if (h_StyleData.type == H_StyleData.TYPE.PETTING)
			{
				this.styles_petting.Add(h_StyleData);
			}
		}
		if (h_scene.mainMembers != null)
		{
			Female female = h_scene.mainMembers.GetFemale(0);
			bool active;
			if (female.HeroineID != HEROINE.MARIKO)
			{
				active = (GlobalData.PlayData.Progress >= GamePlayData.PROGRESS.CLEAR_MAIN);
				if (female.personality.state == Personality.STATE.FIRST || female.personality.state == Personality.STATE.FLIP_FLOP || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_1 || female.personality.state == Personality.STATE.LAST_EVENT_SISTERS || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_2)
				{
					active = false;
				}
			}
			else
			{
				active = (GlobalData.PlayData.Progress >= GamePlayData.PROGRESS.ALL_FREE);
				if (female.personality.state == Personality.STATE.FIRST || female.personality.state == Personality.STATE.FLIP_FLOP || female.personality.state == Personality.STATE.LAST_EVENT_MARIKO)
				{
					active = false;
				}
			}
			for (int i = 0; i < this.stateToggles.Length; i++)
			{
				this.stateToggles[i].gameObject.SetActive(active);
			}
			if (female.personality.weakness)
			{
				this.nowState = H_StyleData.STATE.WEAKNESS;
			}
			else if (!female.IsFloped())
			{
				this.nowState = H_StyleData.STATE.RESIST;
			}
			else
			{
				this.nowState = H_StyleData.STATE.FLOP;
			}
		}
		this.invoke = false;
		for (int j = 0; j < this.stateToggles.Length; j++)
		{
			this.stateToggles[j].ChangeValue(j == (int)this.nowState, false);
		}
		this.genreToggles[0].ChangeValue(true, false);
		this.ChangeGenre(H_StyleData.TYPE.INSERT);
		this.invoke = true;
	}

	// Token: 0x06000E4B RID: 3659 RVA: 0x00059538 File Offset: 0x00057738
	private void UpdateState()
	{
		if (this.h_scene.mainMembers != null)
		{
			Female female = this.h_scene.mainMembers.GetFemale(0);
			bool flag;
			if (female.HeroineID != HEROINE.MARIKO)
			{
				flag = (GlobalData.PlayData.Progress >= GamePlayData.PROGRESS.CLEAR_MAIN);
				if (female.personality.state == Personality.STATE.FIRST || female.personality.state == Personality.STATE.FLIP_FLOP || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_1 || female.personality.state == Personality.STATE.LAST_EVENT_SISTERS || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_2)
				{
					flag = false;
				}
			}
			else
			{
				flag = (GlobalData.PlayData.Progress >= GamePlayData.PROGRESS.ALL_FREE);
				if (female.personality.state == Personality.STATE.FIRST || female.personality.state == Personality.STATE.FLIP_FLOP || female.personality.state == Personality.STATE.LAST_EVENT_MARIKO)
				{
					flag = false;
				}
			}
			if (flag)
			{
				return;
			}
			if (female.personality.weakness)
			{
				this.nowState = H_StyleData.STATE.WEAKNESS;
			}
			else if (!female.IsFloped())
			{
				this.nowState = H_StyleData.STATE.RESIST;
			}
			else
			{
				this.nowState = H_StyleData.STATE.FLOP;
			}
		}
	}

	// Token: 0x06000E4C RID: 3660 RVA: 0x0005966C File Offset: 0x0005786C
	public void UpdateList()
	{
		this.UpdateState();
		this.ChangeGenre(this.nowType);
	}

	// Token: 0x06000E4D RID: 3661 RVA: 0x00059680 File Offset: 0x00057880
	private void ChangeGenre(H_StyleData.TYPE type)
	{
		this.nowType = type;
		this.ChangeList();
	}

	// Token: 0x06000E4E RID: 3662 RVA: 0x00059690 File Offset: 0x00057890
	private void ChangeState(H_StyleData.STATE state)
	{
		this.nowState = state;
		this.ChangeList();
	}

	// Token: 0x06000E4F RID: 3663 RVA: 0x000596A0 File Offset: 0x000578A0
	private void ChangeList()
	{
		if (this.selects != null)
		{
			for (int i = 0; i < this.selects.Length; i++)
			{
				UnityEngine.Object.Destroy(this.selects[i].gameObject);
			}
			this.selects = null;
		}
		List<H_StyleData> list = null;
		if (this.nowType == H_StyleData.TYPE.INSERT)
		{
			list = this.styles_inset;
		}
		else if (this.nowType == H_StyleData.TYPE.SERVICE)
		{
			list = this.styles_service;
		}
		else if (this.nowType == H_StyleData.TYPE.PETTING)
		{
			list = this.styles_petting;
		}
		this.nowStyles.Clear();
		for (int j = 0; j < list.Count; j++)
		{
			if (this.StyleCheck(list[j]))
			{
				this.nowStyles.Add(list[j]);
			}
		}
		this.selects = new Toggle[this.nowStyles.Count];
		for (int k = 0; k < this.nowStyles.Count; k++)
		{
			this.selects[k] = UnityEngine.Object.Instantiate<Toggle>(this.selectOriginal);
			this.selects[k].onValueChanged.AddListener(new UnityAction<bool>(this.OnChangeSelect));
			this.selects[k].gameObject.SetActive(true);
			this.selects[k].transform.SetParent(this.selectsRoot, false);
			this.selects[k].GetComponentInChildren<Text>().text = this.nowStyles[k].name;
		}
		this.selectsRoot.anchoredPosition = Vector2.zero;
	}

	// Token: 0x06000E50 RID: 3664 RVA: 0x0005983C File Offset: 0x00057A3C
	private bool StyleCheck(H_StyleData data)
	{
		Female female = this.h_scene.mainMembers.GetFemale(0);
		if (female.personality.state == Personality.STATE.FIRST || female.personality.state == Personality.STATE.FLIP_FLOP || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_1 || female.personality.state == Personality.STATE.LAST_EVENT_SISTERS || female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_2 || female.personality.state == Personality.STATE.LAST_EVENT_MARIKO)
		{
			return this.StyleCheck_Event(female, data);
		}
		if (data.member == H_StyleData.MEMBER.M1F2)
		{
			if (GlobalData.PlayData.Progress < GamePlayData.PROGRESS.CLEAR_MAIN)
			{
				return false;
			}
			if (this.h_scene.visitor == null || this.h_scene.visitor.GetHuman().sex == SEX.MALE)
			{
				return false;
			}
			if (this.h_scene.visitor.GetFemale().HeroineID == HEROINE.MARIKO && GlobalData.PlayData.Progress < GamePlayData.PROGRESS.ALL_FREE)
			{
				return false;
			}
		}
		if ((data.detailFlag & 2048) != 0)
		{
			if (GlobalData.PlayData.Progress < GamePlayData.PROGRESS.CLEAR_MAIN)
			{
				return false;
			}
			if (female.HeroineID == HEROINE.MARIKO && GlobalData.PlayData.Progress < GamePlayData.PROGRESS.ALL_FREE)
			{
				return false;
			}
		}
		return data.state == this.nowState && (data.map.Length <= 0 || this.h_scene.map.name.IndexOf(data.map) == 0) && this.h_scene.CheckEnableStyle(data.id);
	}

	// Token: 0x06000E51 RID: 3665 RVA: 0x000599E8 File Offset: 0x00057BE8
	private bool StyleCheck_Event(Female female, H_StyleData data)
	{
		if (female.personality.weakness && data.state != H_StyleData.STATE.WEAKNESS)
		{
			return false;
		}
		if (!female.personality.weakness && data.state == H_StyleData.STATE.WEAKNESS)
		{
			return false;
		}
		if (female.personality.state == Personality.STATE.FIRST)
		{
			string[,] array = new string[4, 8];
			array[0, 0] = "HS_00_00_08";
			array[0, 1] = "HS_01_00_06";
			array[0, 2] = "HH_01_00_01";
			array[0, 3] = "HA_00_00_00";
			array[0, 4] = "HS_00_02_08";
			array[0, 5] = "HS_01_02_06";
			array[0, 6] = "HH_01_02_01";
			array[0, 7] = "HA_00_02_00";
			array[1, 0] = "HS_00_00_00";
			array[1, 1] = "HS_01_00_00";
			array[1, 2] = "HH_01_00_00";
			array[1, 3] = "HA_00_00_01";
			array[1, 4] = "HS_00_02_00";
			array[1, 5] = "HS_01_02_00";
			array[1, 6] = "HH_01_02_00";
			array[1, 7] = "HA_00_02_01";
			array[2, 0] = "HS_00_00_02";
			array[2, 1] = "HS_01_00_03";
			array[2, 2] = "HH_03_00_02";
			array[2, 3] = "HA_01_00_00";
			array[2, 4] = "HS_00_02_02";
			array[2, 5] = "HS_01_02_03";
			array[2, 6] = "HH_03_02_02";
			array[2, 7] = "HA_01_02_00";
			array[3, 0] = "HM_00_00_01";
			array[3, 1] = "HM_01_00_01";
			array[3, 2] = string.Empty;
			array[3, 3] = string.Empty;
			array[3, 4] = string.Empty;
			array[3, 5] = "HM_00_02_01";
			array[3, 6] = string.Empty;
			array[3, 7] = string.Empty;
			string[,] array2 = array;
			int heroineID = (int)female.HeroineID;
			for (int i = 0; i < 8; i++)
			{
				if (data.id == array2[heroineID, i])
				{
					return true;
				}
			}
			return false;
		}
		if (female.personality.state == Personality.STATE.FLIP_FLOP)
		{
			string[,] array3 = new string[4, 8];
			array3[0, 0] = "HS_00_01_00";
			array3[0, 1] = "HS_01_01_06";
			array3[0, 2] = "HH_01_00_00";
			array3[0, 3] = "HA_01_00_03";
			array3[0, 4] = "HS_00_02_00";
			array3[0, 5] = "HS_01_02_06";
			array3[0, 6] = "HH_01_02_00";
			array3[0, 7] = "HA_01_02_03";
			array3[1, 0] = "HS_00_00_01";
			array3[1, 1] = "HS_01_00_06";
			array3[1, 2] = "HH_01_00_01";
			array3[1, 3] = "HA_00_00_00";
			array3[1, 4] = "HS_00_02_01";
			array3[1, 5] = "HS_01_02_06";
			array3[1, 6] = "HH_01_02_01";
			array3[1, 7] = "HA_00_02_00";
			array3[2, 0] = "HS_00_01_01";
			array3[2, 1] = "HS_01_01_00";
			array3[2, 2] = "HH_00_01_00";
			array3[2, 3] = "HA_00_01_02";
			array3[2, 4] = "HS_00_02_01";
			array3[2, 5] = "HS_01_02_00";
			array3[2, 6] = "HH_00_02_00";
			array3[2, 7] = "HA_00_02_02";
			array3[3, 0] = "HS_20_01_08";
			array3[3, 1] = "HS_01_01_11";
			array3[3, 2] = "HH_06_01_00";
			array3[3, 3] = "HA_03_01_00";
			array3[3, 4] = "HS_20_02_08";
			array3[3, 5] = string.Empty;
			array3[3, 6] = string.Empty;
			array3[3, 7] = string.Empty;
			string[,] array4 = array3;
			int heroineID2 = (int)female.HeroineID;
			for (int j = 0; j < 8; j++)
			{
				if (data.id == array4[heroineID2, j])
				{
					return true;
				}
			}
			return false;
		}
		if (female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_1)
		{
			string[] array5 = new string[]
			{
				"HS_00_01_06",
				"HS_01_01_03",
				"HH_02_01_00",
				"HA_00_01_01",
				"HS_00_02_06",
				"HS_01_02_03",
				"HH_02_02_00",
				"HA_00_02_01"
			};
			for (int k = 0; k < array5.Length; k++)
			{
				if (data.id == array5[k])
				{
					return true;
				}
			}
			return false;
		}
		if (female.personality.state == Personality.STATE.LAST_EVENT_SISTERS)
		{
			string[] array6 = new string[]
			{
				"HW_00_01_00",
				"HW_00_02_00"
			};
			for (int l = 0; l < array6.Length; l++)
			{
				if (data.id == array6[l])
				{
					return true;
				}
			}
			return false;
		}
		if (female.personality.state == Personality.STATE.LAST_EVENT_YUKIKO_2)
		{
			string[] array7 = new string[]
			{
				"HS_10_01_00",
				"HH_10_01_00",
				"HA_10_01_00",
				"HS_10_02_00",
				"HH_10_02_00",
				"HA_10_02_00"
			};
			for (int m = 0; m < array7.Length; m++)
			{
				if (data.id == array7[m])
				{
					return true;
				}
			}
			return false;
		}
		if (female.personality.state == Personality.STATE.LAST_EVENT_MARIKO)
		{
			string[] array8 = new string[]
			{
				"HS_20_01_09",
				"HS_01_00_01",
				"HH_01_01_01",
				"HA_00_01_01",
				"HS_20_02_09",
				"HS_01_02_01"
			};
			for (int n = 0; n < array8.Length; n++)
			{
				if (data.id == array8[n])
				{
					return true;
				}
			}
			return false;
		}
		return false;
	}

	// Token: 0x06000E52 RID: 3666 RVA: 0x00059FF0 File Offset: 0x000581F0
	public void Close()
	{
		if (this.middleLeftGroup.Value == 0)
		{
			this.mainToggle.ChangeValue(false, false);
			this.middleLeftGroup.Change(-1, false);
		}
	}

	// Token: 0x06000E53 RID: 3667 RVA: 0x0005A01C File Offset: 0x0005821C
	private void OnChangeMainToggle(bool change)
	{
		this.hideableRoot.SetActive(change);
		if (change)
		{
			this.UpdateList();
		}
	}

	// Token: 0x06000E54 RID: 3668 RVA: 0x0005A038 File Offset: 0x00058238
	private void OnChangeGenre_Insert(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeGenre(H_StyleData.TYPE.INSERT);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E55 RID: 3669 RVA: 0x0005A058 File Offset: 0x00058258
	private void OnChangeGenre_Service(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeGenre(H_StyleData.TYPE.SERVICE);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E56 RID: 3670 RVA: 0x0005A078 File Offset: 0x00058278
	private void OnChangeGenre_Petting(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeGenre(H_StyleData.TYPE.PETTING);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E57 RID: 3671 RVA: 0x0005A098 File Offset: 0x00058298
	private void OnChangeGenre_Resist(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeState(H_StyleData.STATE.RESIST);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E58 RID: 3672 RVA: 0x0005A0B8 File Offset: 0x000582B8
	private void OnChangeGenre_Flop(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeState(H_StyleData.STATE.FLOP);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E59 RID: 3673 RVA: 0x0005A0D8 File Offset: 0x000582D8
	private void OnChangeGenre_Weakness(bool change)
	{
		if (this.invoke && change)
		{
			this.ChangeState(H_StyleData.STATE.WEAKNESS);
			SystemSE.Play(SystemSE.SE.CHOICE);
		}
	}

	// Token: 0x06000E5A RID: 3674 RVA: 0x0005A0F8 File Offset: 0x000582F8
	private void OnChangeSelect(bool flag)
	{
		if (this.invoke && flag)
		{
			for (int i = 0; i < this.selects.Length; i++)
			{
				if (this.selects[i].isOn)
				{
					this.ChangeSelect(i);
					break;
				}
			}
		}
	}

	// Token: 0x06000E5B RID: 3675 RVA: 0x0005A150 File Offset: 0x00058350
	private void ChangeSelect(int no)
	{
		ScreenFade.StartFade(ScreenFade.TYPE.OUT_IN, Color.black, 0.5f, 0f, delegate
		{
			this.h_scene.ChangeStyle(this.nowStyles[no].id);
		}, true);
		SystemSE.Play(SystemSE.SE.YES);
	}

	// Token: 0x04000EBF RID: 3775
	[SerializeField]
	private ToggleButton mainToggle;

	// Token: 0x04000EC0 RID: 3776
	[SerializeField]
	private ToggleButton[] genreToggles = new ToggleButton[3];

	// Token: 0x04000EC1 RID: 3777
	[SerializeField]
	private ToggleButton[] stateToggles = new ToggleButton[3];

	// Token: 0x04000EC2 RID: 3778
	[SerializeField]
	private GameObject hideableRoot;

	// Token: 0x04000EC3 RID: 3779
	[SerializeField]
	private RectTransform selectsRoot;

	// Token: 0x04000EC4 RID: 3780
	[SerializeField]
	private Toggle selectOriginal;

	// Token: 0x04000EC5 RID: 3781
	private Toggle[] selects;

	// Token: 0x04000EC6 RID: 3782
	[SerializeField]
	private RadioButtonGroup middleLeftGroup;

	// Token: 0x04000EC7 RID: 3783
	private Dictionary<string, H_StyleData> stylesDictionary;

	// Token: 0x04000EC8 RID: 3784
	private List<H_StyleData> styles_inset = new List<H_StyleData>();

	// Token: 0x04000EC9 RID: 3785
	private List<H_StyleData> styles_service = new List<H_StyleData>();

	// Token: 0x04000ECA RID: 3786
	private List<H_StyleData> styles_petting = new List<H_StyleData>();

	// Token: 0x04000ECB RID: 3787
	private bool invoke = true;

	// Token: 0x04000ECC RID: 3788
	private H_StyleData.TYPE nowType;

	// Token: 0x04000ECD RID: 3789
	private H_StyleData.STATE nowState = H_StyleData.STATE.UNKNOWN;

	// Token: 0x04000ECE RID: 3790
	private List<H_StyleData> nowStyles = new List<H_StyleData>();

	// Token: 0x04000ECF RID: 3791
	private H_Scene h_scene;
}
